package com.hq.useBatis.controller;

import com.hq.useBatis.entity.Student;
import com.hq.useBatis.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Auther: fsxa
 * @Date: 2018/12/17 15:56
 * @Description:
 */
@Controller
public class StudentController {
    @Autowired
    private StudentMapper studentMapper;

    @RequestMapping("/get")
    @ResponseBody
    public Student getStudent(@RequestParam(required = false,defaultValue = "1") Integer id){
        return studentMapper.findById(id);
    }

    @RequestMapping("/list")
    public String getList(Model model) {
        System.out.println("list ..." );
        List<Student> list = studentMapper.findAll();
        model.addAttribute("list",list);
        return "list";
    }

}
